﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class AquacultureGuiGeAddControl : YuanlinUserControl
    {
        protected ValuedTextBox titleValuedTextBox;
        protected ValuedTextBox companyValuedTextBox;

        protected IButton SaveButton;
        protected IButton BackButton;
        private int categoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryId);
        private int categoryType = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryType);

        protected override void OnLoad(EventArgs e)
        {
            SaveButton.Attributes["onclick"] = "return CheckValue()";
            SaveButton.Click += new EventHandler(SaveButton_Click);
            BackButton.Click += new EventHandler(BackButton_Click);
        }

        public void BackButton_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect(SiteUrls.Instance().GetAquacultureGuiGeListUrl(categoryId, categoryType));
        }

        public void SaveButton_Click(object sender, EventArgs e)
        {
            AquacultureGuiGe aquacultureGuiGe = new AquacultureGuiGe();

            aquacultureGuiGe.CategoryId.Value = categoryId;
            aquacultureGuiGe.Title.Value = CensorWordManager.CensorWord(this.titleValuedTextBox.Value);
            aquacultureGuiGe.Unit.Value = CensorWordManager.CensorWord(this.companyValuedTextBox.Value);

            if (BusinessManager.CreateAquacultureGuiGe(aquacultureGuiGe) == -2)
            {
                Globals.ShowMessage(this.Page, "添加失败", "此信息已经存在！");
                return;
            }

            Page.Response.Redirect(SiteUrls.Instance().GetAquacultureGuiGeListUrl(categoryId, categoryType));
        }
    }
}